package com.dotdotcode.testmodule;

import com.dotdotcode.sdk.service.ISdkService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ServiceLoader;

@SpringBootApplication
public class TestModuleApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(TestModuleApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        ServiceLoader<ISdkService> weatherServices = ServiceLoader.load(ISdkService.class);
        // 虽然测试项目中同时引入了 sdk 和 third-sdk 项目，但是sdk中的 DefaultSdkServiceImpl 并不会被实例化
        // 另外，由于jdk的spi机制并没有实现选择性的实例化接口实现对象，如果实例化过多会造成比较多的浪费。而apache的Dubbo有更高级的实现
        for (ISdkService service : weatherServices) {
            service.service();
        }
    }
}
